<title>进货价设置</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>销售管理</cite></a>
        <a><cite>进货价设置</cite></a>
    </div>
</div>

<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto" lay-filter="app-content-list">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">店铺名称</label>
                    <div class="layui-input-inline">
                        <select name="mallId" id="buyprice-mall-list" lay-filter="buyprice-mall-filter">
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">商品名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="productName" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">sku货号</label>
                    <div class="layui-input-inline">
                        <input type="text" name="skuExtCode" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">skuId</label>
                    <div class="layui-input-inline">
                        <input type="text" name="productSkuId" placeholder="请输入" autocomplete="off"
                               class="layui-input">
                    </div>
                </div>

                <div class="layui-inline">
                    <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                        <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                    </button>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="LAY-temu-buyprice-list" lay-filter="LAY-temu-buyprice-list">
            </table>
        </div>
    </div>
</div>
<script>
    layui.use('contlist', layui.factory('contlist')).use(['admin', 'contlist', 'table'], function () {
        var $ = layui.$
            , admin = layui.admin
            , view = layui.view
            , table = layui.table
            , form = layui.form
            , setter = layui.setter
            , request = layui.request;
        admin.req({
            url: '/temu/queryMallList',
            type: 'post',
            done: function (data) {
                $.each(data.data, function (index, item) {
                    $('#buyprice-mall-list').append(new Option(item.mallName, item.mallId));// 下拉菜单里添加元素
                });
                form.render(null, 'app-content-list');

                table.render({
                    elem: '#LAY-temu-buyprice-list'
                    , url: '/temu/queryWarehouse'
                    // , url: '/temu/syncWarehouse'
                    , headers: {'access_token': layui.data(setter.tableName)[setter.request.tokenName]}
                    , where: {mallId: $("#buyprice-mall-list option:selected").val()}
                    , method: 'post'
                    // , height: '600'
                    , height: 'full-250'
                    , lineStyle: 'height: 151px;'
                    , cols: [[
                        {
                            field: 'productSkcPicture',
                            width: 150,
                            title: '商品',
                            align: 'center',
                            templet: function (d) {
                                return '<img src="' + d.productSkcPicture + '"/>'
                            }
                        }
                        , {field: 'className', align: 'center', title: 'sku属性'}
                        , {field: 'skuExtCode', align: 'center', title: 'sku货号'}
                        , {
                            field: 'supplierPrice',
                            title: '申报价格',
                            align: 'center',
                        }
                        , {
                            field: 'buyingPrice',
                            align: 'center',
                            title: '进货价',
                            edit: 'text'
                        }

                        // ,{title: '操作', minWidth: 150, align: 'center', fixed: 'right', toolbar: '#table-content-list'}
                    ]]
                    , text: {none:'暂无数据'}
                });
            }
        });


        // form.render('select', 'app-content-list');
        //搜索

        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            table.render({
                elem: '#LAY-temu-buyprice-list'
                , url: '/temu/queryWarehouse' //模拟接口
                , headers: {'access_token': layui.data(setter.tableName)[setter.request.tokenName]}
                , where: {mallId: $("#buyprice-mall-list option:selected").val(),skuExtCode:data.field.skuExtCode,productSkuId:data.field.productSkuId,productName:data.field.productName}
                , method: 'post'
                // , height: '600'
                , height: 'full-250'
                , lineStyle: 'height: 151px;'
                , cols: [[{
                    field: 'productSkcPicture',
                    width: 150,
                    title: '商品',
                    align: 'center',
                    templet: function (d) {
                        return '<img src="' + d.productSkcPicture + '"/>'
                    }
                }
                    , {field: 'className', align: 'center', title: 'sku属性'}
                    , {field: 'skuExtCode', align: 'center', title: 'sku货号'}
                    , {
                        field: 'supplierPrice',
                        align: 'center',
                        title: '申报价格',
                    }
                    , {
                        field: 'buyingPrice',
                        title: '进货价',
                        align: 'center',
                        edit: 'text'
                    }]]
                , text: '对不起，加载出现异常！'
            });
        });
        table.on('edit(LAY-temu-buyprice-list)', function (obj) {
            var value = obj.value // 得到修改后的值
            var data = obj.data // 得到所在行所有键值
            var field = obj.field; // 得到字段

            // 更新数据中对应的字段
            var update = {};
            update[field] = value;
            obj.update(update);
            console.log(data);
            console.log(field)
            // 编辑后续操作，如提交更新请求，以完成真实的数据更新
            // …
            admin.req({
                url: '/temu/updateBuyPrice',
                type: 'post',
                data: {skuExtCode: data.skuExtCode, buyingPrice: value},
                done: function (res) {
                    showData(res);
                }
            });
            // 显示当前行最新数据 - 仅用于示例展示

        });
        form.on('select(buyprice-mall-filter)', function (data) {
            table.reload('LAY-temu-buyprice-list', {
                where: {mallId: data.value}
            });
        });
        var showData = function (data) {
            return layer.msg('当前行最新数据：<br>' + util.escape(JSON.stringify(data)), {
                offset: '16px',
                anim: 'slideDown'
            });
        };
    });
</script>
